<template>
  <div>
    <div class="background">
      <div class="particles"></div>
      <div class="glow"></div>
      <div class="glow"></div>
      <div class="glow"></div>
      <div class="floating-elements">
        <div class="element" v-for="n in 5" :key="n"></div>
      </div>
    </div>

    <header class="header">
      <div class="logo">
        <i class="fas fa-gamepad"></i>
        <span>放松小游戏</span>
      </div>
      <nav class="nav-links">
        <a href="#home">首页</a>
        <a href="#section1">游戏</a>
      </nav>
    </header>

    <main>
      <section class="hero">
        <div class="hero-content">
          <h1>探索HTML游戏世界</h1>
          <p>发现益智游戏，感受非凡体验</p>
        </div>
      </section>

      <section class="game-categories">
        <div class="category-card" v-for="(game, index) in gameCategories" :key="index">
          <div class="category-icon">
            <i :class="game.icon"></i>
          </div>
          <h3 :id="game.id">{{ game.title }}</h3>
          <p>{{ game.description }}</p>
          <a :href="game.link" class="game-link">探索游戏</a>
        </div>
      </section>

      <section class="featured-games">
        <h4>梦想的路上，坚持是我们最坚固的盔甲，勇气是我们最锋利的武器</h4>
        <div class="game-slider" ref="gameSlider"></div>
      </section>
    </main>
  </div>
</template>

<script>
export default {
  name: 'GameIndex',
  data() {
    return {
      angle: 0,
      lastScroll: 0,
      currentGame: 0,
      gameCategories: [
        {
          id: 'section1',
          title: '反应与色感碰撞',
          description: '',
          icon: 'fas fa-sword',
          link: 'find color.html'
        },
        {
          title: '智慧与记忆迸发',
          description: '',
          icon: 'fas fa-brain',
          link: 'remember.html'
        },
        {
          title: '手速与技巧竞速',
          description: '',
          icon: 'fas fa-ghost',
          link: 'mark.html'
        },
        {
          title: '经典与创新相融',
          description: '',
          icon: 'fas fa-chess',
          link: 'snake-game.html'
        }
      ],
      featuredGames: [
        {
          title: "暗影之刃",
          genre: "动作冒险",
          rating: "9.5分",
          image: "https://via.placeholder.com/300x400"
        },
        {
          title: "星际指挥官",
          genre: "策略游戏",
          rating: "9.2分",
          image: "https://via.placeholder.com/300x400"
        },
        {
          title: "午夜惊魂",
          genre: "恐怖惊悚",
          rating: "8.9分",
          image: "https://via.placeholder.com/300x400"
        }
      ]
    }
  },
  mounted() {
    this.initFloatingElements();
    this.initMouseMoveEffect();
    this.initBackgroundAnimation();
    this.initScrollEffect();
    this.initSmoothScroll();
    this.initGameCardAnimation();
    this.updateGamePreview();
    this.initGameSlider();
    this.initGameLinkEffect();
    
    // 添加页面加载动画
    document.body.classList.add('loaded');
  },
  methods: {
    // 初始化浮动元素
    initFloatingElements() {
      const elements = document.querySelectorAll('.element');
      elements.forEach((element) => {
        // 随机大小
        const size = Math.random() * 20 + 10;
        element.style.width = `${size}px`;
        element.style.height = `${size}px`;

        // 随机位置
        const x = Math.random() * 100;
        const y = Math.random() * 100;
        element.style.left = `${x}%`;
        element.style.top = `${y}%`;

        // 随机动画延迟
        const delay = Math.random() * 5;
        element.style.animationDelay = `${delay}s`;

        // 随机动画持续时间
        const duration = Math.random() * 10 + 10;
        element.style.animationDuration = `${duration}s`;
      });
    },
    
    // 鼠标移动效果
    initMouseMoveEffect() {
      document.addEventListener('mousemove', (e) => {
        const glowElements = document.querySelectorAll('.glow');
        const x = e.clientX / window.innerWidth;
        const y = e.clientY / window.innerHeight;

        glowElements.forEach((glow) => {
          const moveX = (x - 0.5) * 50;
          const moveY = (y - 0.5) * 50;
          glow.style.transform = `translate(${moveX}px, ${moveY}px)`;
        });
      });
    },
    
    // 背景网格动画
    initBackgroundAnimation() {
      const particles = document.querySelector('.particles');
      const updateGrid = () => {
        this.angle += 0.5;
        particles.style.background = `
          radial-gradient(circle at ${50 + Math.sin(this.angle) * 20}% ${50 + Math.cos(this.angle) * 20}%, 
          rgba(0, 255, 157, 0.1) 0%, transparent 20%),
          radial-gradient(circle at ${50 + Math.cos(this.angle) * 20}% ${50 + Math.sin(this.angle) * 20}%, 
          rgba(0, 255, 157, 0.1) 0%, transparent 20%)
        `;
        requestAnimationFrame(updateGrid);
      };
      updateGrid();
    },
    
    // 滚动效果
    initScrollEffect() {
      const header = document.querySelector('.header');
      
      window.addEventListener('scroll', () => {
        const currentScroll = window.pageYOffset;

        if (currentScroll <= 0) {
          header.classList.remove('scroll-up');
          return;
        }

        if (currentScroll > this.lastScroll && !header.classList.contains('scroll-down')) {
          // 向下滚动
          header.classList.remove('scroll-up');
          header.classList.add('scroll-down');
        } else if (currentScroll < this.lastScroll && header.classList.contains('scroll-down')) {
          // 向上滚动
          header.classList.remove('scroll-down');
          header.classList.add('scroll-up');
        }
        this.lastScroll = currentScroll;
      });
    },
    
    // 平滑滚动
    initSmoothScroll() {
      document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
          e.preventDefault();
          const target = document.querySelector(this.getAttribute('href'));
          if (target) {
            target.scrollIntoView({
              behavior: 'smooth',
              block: 'start'
            });
          }
        });
      });
    },
    
    // 游戏卡片动画
    initGameCardAnimation() {
      const categoryCards = document.querySelectorAll('.category-card');
      const observerOptions = {
        threshold: 0.1
      };

      const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
          if (entry.isIntersecting) {
            entry.target.classList.add('animate');
          }
        });
      }, observerOptions);

      categoryCards.forEach(card => {
        observer.observe(card);
      });
    },
    
    // 更新游戏预览
    updateGamePreview() {
      const game = this.featuredGames[this.currentGame];
      if (this.$refs.gameSlider) {
        this.$refs.gameSlider.innerHTML = `
          <div class="game-preview">
            <img src="${game.image}" alt="${game.title}">
            <div class="game-info">
              <h3>${game.title}</h3>
              <p>${game.genre} | ${game.rating}</p>
            </div>
          </div>
        `;
      }
    },
    
    // 初始化游戏轮播
    initGameSlider() {
      // 每5秒切换一次热门游戏
      setInterval(() => {
        this.currentGame = (this.currentGame + 1) % this.featuredGames.length;
        this.updateGamePreview();
      }, 5000);
    },
    
    // 游戏链接点击效果
    initGameLinkEffect() {
      const gameLinks = document.querySelectorAll('.game-link');
      gameLinks.forEach(link => {
        link.addEventListener('click', function (e) {
          e.preventDefault();
          this.classList.add('clicked');
          setTimeout(() => {
            window.location.href = this.getAttribute('href');
          }, 300);
        }); 
      });
    }
  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
  color: #fff;
  overflow-x: hidden;
  background-color: #0a0a0a;
}

/* 背景动画 */
.background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  z-index: -2;
}

.particles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.1) 0%, transparent 20%),
    radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.1) 0%, transparent 20%);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(0, 255, 157, 0.1) 0%, transparent 20%),
    radial-gradient(circle at 80% 70%, rgba(0, 255, 157, 0.1) 0%, transparent 20%);
  animation: particles 20s linear infinite;
}

.particles::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 50% 50%, rgba(0, 255, 157, 0.05) 0%, transparent 30%),
    repeating-linear-gradient(45deg, transparent 0px, transparent 2px, rgba(0, 255, 157, 0.03) 2px, rgba(0, 255, 157, 0.03) 4px);
  animation: grid 20s linear infinite;
}

.particles::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 30% 70%, rgba(0, 255, 157, 0.05) 0%, transparent 25%),
    repeating-linear-gradient(-45deg, transparent 0px, transparent 2px, rgba(0, 255, 157, 0.03) 2px, rgba(0, 255, 157, 0.03) 4px);
  animation: grid 20s linear infinite reverse;
}

@keyframes particles {
  0% {
    transform: translate(0, 0);
  }

  100% {
    transform: translate(100px, 100px);
  }
}

@keyframes grid {
  0% {
    transform: translate(0, 0);
  }

  100% {
    transform: translate(50px, 50px);
  }
}

/* 添加动态光效 */
.glow {
  position: absolute;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 255, 157, 0.2) 0%, transparent 70%);
  filter: blur(20px);
  animation: glowMove 15s ease-in-out infinite;
}

.glow:nth-child(1) {
  top: 20%;
  left: 20%;
  animation-delay: 0s;
}

.glow:nth-child(2) {
  top: 60%;
  left: 60%;
  animation-delay: -5s;
}

.glow:nth-child(3) {
  top: 40%;
  left: 80%;
  animation-delay: -10s;
}

@keyframes glowMove {

  0%,
  100% {
    transform: translate(0, 0) scale(1);
  }

  25% {
    transform: translate(50px, 50px) scale(1.2);
  }

  50% {
    transform: translate(0, 100px) scale(1);
  }

  75% {
    transform: translate(-50px, 50px) scale(0.8);
  }
}

/* 导航栏样式 */
.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  padding: 1rem 2rem;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  font-size: 1.5rem;
  font-weight: bold;
  color: #fff;
}

.logo i {
  color: #00ff9d;
  margin-right: 0.5rem;
  font-size: 2rem;
}

.nav-links {
  display: flex;
  gap: 2rem;
}

.nav-links a {
  color: #fff;
  text-decoration: none;
  font-weight: 500;
  position: relative;
  padding: 0.5rem 0;
}

.nav-links a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: #00ff9d;
  transition: width 0.3s ease;
}

.nav-links a:hover::after {
  width: 100%;
}

/* 英雄区域样式 */
.hero {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 1rem;
  position: relative;
}

.hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, rgba(0, 255, 157, 0.1), rgba(0, 0, 0, 0.5));
  z-index: -1;
}

.hero-content {
  max-width: 800px;
}

.hero h1 {
  font-size: 4rem;
  margin-bottom: 1rem;
  text-shadow: 0 0 10px rgba(0, 255, 157, 0.5);
  animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
  from {
    text-shadow: 0 0 10px rgba(0, 255, 157, 0.5);
  }

  to {
    text-shadow: 0 0 20px rgba(0, 255, 157, 0.8);
  }
}

.hero p {
  font-size: 1.5rem;
  color: #ccc;
}

/* 游戏分类样式 */
.game-categories {
  padding: 5rem 2rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.category-card {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  border-radius: 15px;
  padding: 2rem;
  text-align: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  position: relative;
  overflow: hidden;
}

.category-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, transparent, rgba(0, 255, 157, 0.1));
  z-index: -1;
}

.category-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 10px 20px rgba(0, 255, 157, 0.2);
}

.category-icon {
  font-size: 3rem;
  color: #00ff9d;
  margin-bottom: 1rem;
}

.category-card h3 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.category-card p {
  color: #ccc;
  margin-bottom: 1.5rem;
}

.game-link {
  display: inline-block;
  padding: 0.8rem 2rem;
  background: transparent;
  border: 2px solid #00ff9d;
  color: #00ff9d;
  text-decoration: none;
  border-radius: 25px;
  transition: all 0.3s ease;
}

.game-link:hover {
  background: #00ff9d;
  color: #000;
}

/* 热门推荐样式 */
.featured-games {
  padding: 5rem 2rem;
  background: rgba(0, 0, 0, 0.3);
}

.featured-games h4 {
  text-align: center;
  margin-bottom: 3rem;
  font-size: 1.5rem;
}

.game-slider {
  max-width: 1200px;
  margin: 0 auto;
}

.game-preview {
  position: relative;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.game-preview img {
  width: 100%;
  height: auto;
  transition: transform 0.3s ease;
}

.game-preview:hover img {
  transform: scale(1.05);
}

.game-info {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 2rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
}

.game-info h3 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.game-info p {
  color: #00ff9d;
}

/* 页脚样式 */
.footer {
  background: rgba(0, 0, 0, 0.5);
  padding: 3rem 2rem 1rem;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 2rem;
}

.footer-section h3 {
  color: #00ff9d;
  margin-bottom: 1rem;
}

.social-links {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
}

.social-links a {
  color: #fff;
  font-size: 1.5rem;
  transition: color 0.3s ease;
}

.social-links a:hover {
  color: #00ff9d;
}

.footer-bottom {
  text-align: center;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    padding: 1rem;
  }

  .nav-links {
    margin-top: 1rem;
    flex-wrap: wrap;
    justify-content: center;
  }

  .hero h1 {
    font-size: 2.5rem;
  }

  .hero p {
    font-size: 1.2rem;
  }

  .game-categories {
    grid-template-columns: 1fr;
  }
}

/* 添加卡片动画效果 */
.category-card.animate {
  animation: fadeInUp 0.6s ease forwards;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 链接点击效果 */
.game-link.clicked {
  transform: scale(0.95);
  background: #00ff9d;
  color: #000;
}

/* 页面加载动画 */
body:not(.loaded) {
  opacity: 0;
}

body.loaded {
  opacity: 1;
  transition: opacity 0.5s ease;
}

/* 导航栏滚动效果 */
.header.scroll-down {
  transform: translateY(-100%);
  transition: transform 0.3s ease-in-out;
}

.header.scroll-up {
  transform: translateY(0);
  transition: transform 0.3s ease-in-out;
}

/* 浮动元素 */
.floating-elements {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
}

.element {
  position: absolute;
  background: rgba(0, 255, 157, 0.2);
  border-radius: 50%;
  animation: float 20s linear infinite;
}

@keyframes float {
  0% {
    transform: translate(0, 0) rotate(0deg);
  }
  25% {
    transform: translate(100px, 100px) rotate(90deg);
  }
  50% {
    transform: translate(0, 200px) rotate(180deg);
  }
  75% {
    transform: translate(-100px, 100px) rotate(270deg);
  }
  100% {
    transform: translate(0, 0) rotate(360deg);
  }
}
</style>